package org.hengguan.api.contest.module.contest.controller;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.hengguan.api.contest.exception.OperationException;
import org.hengguan.api.contest.module.contest.vo.RecordVo;
import org.hengguan.api.contest.vo.ResponseVo;
import org.hengguan.base.contest.model.contest.PlayerRecordModel;
import org.hengguan.base.contest.service.contest.PlayerRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = {"档案"})
@RestController
@RequestMapping("/record")
public class RecordController {

    @Autowired
    private PlayerRecordService playerRecordService;

    @ApiOperationSupport(includeParameters = {
            "plName",
            "plTelephone",
            "plSex",
            "plAddress"
    })
    @ApiOperation(value = "添加档案",notes = "添加档案")
    @PostMapping("/add")
    public ResponseVo<RecordVo> add(RecordVo recordVo){

//        PlayerRecordModel playerRecordModel = playerRecordService.getOne(new QueryWrapper<PlayerRecordModel>()
//                .eq(StrUtil.isNotBlank(recordVo.getPlTelephone()) ,"pl_telephone", recordVo.getPlTelephone())
//                .last("LIMIT 1")
//        );
//        if (playerRecordModel == null) {
//
//        }else {
//            return ResponseVo.error("信息已存在 : pl_name -> "+playerRecordModel.getPlName()+" , pl_id -> "+playerRecordModel.getId());
//        }
        PlayerRecordModel playerRecordModel = PlayerRecordModel.builder()
                .plName(recordVo.getPlName())
                .plTelephone(recordVo.getPlTelephone())
                .plSex(recordVo.getPlSex())
                .plAddress(recordVo.getPlAddress())
                .build();
        playerRecordModel.insert();
        return ResponseVo.ok(recordVo.setPlId(playerRecordModel.getId()));
    }



}
